<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Root extends CI_Controller {

          public function __construct(){
                        parent::__construct();
                        $this->load->model(array("rootmodel"));
                }


	public function index()
	{
		$departs=$this->rootmodel->get_departs();
		$roles=$this->rootmodel->get_roles();
                       $data=array();
                       $data['departs']=$departs;
                       $data['roles']=$roles;
		load($this->db,$this->session,$this->load,"root","index",$data);
	}


	public function get_root(){//获取所有用户列表
		/*$sql="select * from account ";
		$query=$this->db->query($sql);
		$arr=$query->result_array();*/
		$arr=$this->rootmodel->get_roots();
		//print_r($arr);
	           $str=json_encode($arr);
	           echo $str;
		
	}


	public function adddb(){
                 $arr=$_REQUEST;         
                   $depart=$arr['depart'];
                   $role_id=$arr['role_id'];
                   $realname=$arr['realname'];
                   $phone=$arr['phone'];
                   $username=$arr['username'];
                   $passwd=$arr['passwd'];
                   $arr=array(
                   	"depart"=>$depart,
                   	"role_id"=>$role_id,
                   	"realname"=>$realname,
                   	"phone"=>$phone,
                   	"username"=>$username,
                   	"passwd"=>$passwd
                   	);

                   if($this->db->insert("account",$arr)){
                   	success();
                   }

               
	}


	public function edit(){
                 $arr=$_REQUEST;
                  $id=$arr['id'];
                  $depart=$arr['depart'];
                   $role_id=$arr['role_id'];
                   $realname=$arr['realname'];
                   $phone=$arr['phone'];
                   $username=$arr['username'];
                   $passwd=$arr['passwd'];
                   $sql="update `account` set `depart`='$depart',`role_id`='$role_id',`realname`='$realname',`phone`='$phone',`username`='$username',`passwd`='$passwd' where `id`='$id'";
                   if($this->db->query($sql)){
                   	success();
                   }
                   
	}

	public function del(){
                $id = intval($_REQUEST['id']);
               	 $sql="delete from account where id='$id'";
                          if($this->db->query($sql)){
                         success();
                              }else{}
             
             

	}
}
